package nuonuo.com.view.activity;

import android.animation.ArgbEvaluator;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import nuonuo.com.view.R;
import nuonuo.com.view.activity.PtrActivity;
import nuonuo.com.view.customview.MyAdapter;
import nuonuo.com.view.customview.MyHorizantalScrollerView;
import nuonuo.com.view.customview.OnHideItemClickListener;
import nuonuo.com.view.customview.OnItemClickListener;

public class QQSwipeLayout extends AppCompatActivity {
    private Context mContext;
    private MyHorizantalScrollerView itemView;
    private TextView tvDel;
    private ListView lv;
    private MyAdapter adapter;
    private ValueAnimator animation;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_qqswipe_layout);

        mContext = this;
        lv = (ListView) findViewById(R.id.lv);
        itemView = (MyHorizantalScrollerView) findViewById(R.id.itemview);
        animation = ObjectAnimator.ofInt(itemView,"backgroundColor",0xffff8080,0xff8080ff);
        animation.setDuration(1000);
        animation.setEvaluator(new ArgbEvaluator());
        animation.setRepeatCount(ValueAnimator.INFINITE);
        animation.setRepeatMode(ValueAnimator.REVERSE);
        adapter = new MyAdapter(this);
        lv.setAdapter(adapter);
        tvDel = (TextView) findViewById(R.id.del);
        tvDel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(mContext, "点击了按钮", Toast.LENGTH_SHORT).show();
            }
        });

        adapter.setOnDel1Listener(new OnHideItemClickListener() {
            @Override
            public void onHideItemClick(View v, int position) {
                Toast.makeText(mContext, "del1:::::::::::::::::::"+position, Toast.LENGTH_SHORT).show();
            }
        });
        adapter.setOnDel2Listener(new OnHideItemClickListener() {
            @Override
            public void onHideItemClick(View v, int position) {
                Toast.makeText(mContext, "del2====="+position, Toast.LENGTH_SHORT).show();
            }
        });
        adapter.setOnDel3Listener(new OnHideItemClickListener() {
            @Override
            public void onHideItemClick(View v, int position) {
                Toast.makeText(mContext, "del3-------"+position, Toast.LENGTH_SHORT).show();
            }
        });
        adapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(int position, View v) {
//                startActivity(new Intent(mContext,AnimatorActivity.class));
                if (((MyHorizantalScrollerView)v).getMODE() == MyHorizantalScrollerView.SHOW){
                    ((MyHorizantalScrollerView)v).hideViews();
                }else {
                    Toast.makeText(mContext, "itemView!!!!!!!!!!!!!!!!!!"+position, Toast.LENGTH_SHORT).show();
                }
            }
        });
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                MyHorizantalScrollerView horizantalView = (MyHorizantalScrollerView) view.findViewById(R.id.hide_item);
                if (horizantalView.getMODE() == MyHorizantalScrollerView.SHOW){
                    horizantalView.hideViews();
                }else {
                    Toast.makeText(mContext, "itemView??????????????"+position, Toast.LENGTH_SHORT).show();
                }
            }
        });
    }

    @Override
    protected void onStart() {
        super.onStart();
        animation.start();
    }

    @Override
    protected void onStop() {
        super.onStop();
        animation.end();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        animation.cancel();
        animation = null;
    }
}
